package com.akk.action;

import com.akk.module.avs.entity.AvsLecturer;
import com.akk.module.avs.service.AvsLectureService;
import com.akk.utils.PatternUtil;
import com.akk.utils.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;

/**
 * @company www.lovekaka.com
 * @auther hainlc
 * @create 2017/06/21 11:33
 */
@RestController
@RequestMapping(value = "/thmlfApi/lecture")
public class LectureAction {

    @Autowired
    private AvsLectureService lectureService;


    @GetMapping(value = "/query")
    @Transactional
    public RestResponse query(String ct){
        int type = 1;
        if (PatternUtil.isIdCard(ct))
            type = 0;
        AvsLecturer entity = lectureService.queryByCertificateNumberAndType(ct, type);
        if (entity == null)
            return RestResponse.build("1","未查询到讲师信息");
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        String startTime = format.format(entity.getStartTime());
        String endTime = format.format(entity.getEndTime());
        if (startTime.length() > 10)
            startTime = startTime.substring(0,10);
        if (endTime.length()>10)
            endTime = endTime.substring(0,10);
        entity.setExpiryDate(startTime + " - " + endTime);
        if (entity == null)
            return RestResponse.build("1","未查询到讲师信息");
        return RestResponse.build(entity);
    }
}
